    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ReportExhibitorFinancial.java
 *
 * Created on Dec 3, 2010, 9:24:51 AM
 */
package GUI;

import Business.CalendarDateTime;
import Business.BssGetDataReportExhibitorFinancialList;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;
//import Entity.ReportAttendance1;

/**
 *
 * @author Nguyen Hoang Viet <nguyenhoangvietitt@gmail.com>
 */

/*
 * class ReportExhibitorFinancial
 */
public class ReportExhibitorFinancial extends javax.swing.JFrame {

//    Create a new object of Default ComboBoxModel for combobox Year
    DefaultComboBoxModel mcbxYear = new DefaultComboBoxModel();
//    Create a new object of Default ComboBoxModel for combobox Year
    DefaultComboBoxModel mcbxWeek = new DefaultComboBoxModel();
//    Create a new object of Default ComboBoxTableModel , innitial equals null
    DefaultTableModel model = null;
//    Create a new object of Default ComboBoxTableModel , innitial equals null
//  TextA model = null;

//    Declare a new object type of GetDataReportExhibitorFinancialList, innitial equals null
    BssGetDataReportExhibitorFinancialList att = null;
//    Create a new object of CalendarDateTime
    CalendarDateTime cdt = new CalendarDateTime();

    /** Creates new form ReportAttendance */
//    Create a construct ReportExhibitorFinancial of class ReportExhibitorFinancial
    public ReportExhibitorFinancial() {
//      initComponents is regenerated by the Form Editor
        initComponents();
//        Create a new object of Calendar
        Calendar calendar = new GregorianCalendar();
//        for in 10 year
        for (int i = calendar.get(Calendar.YEAR) - 5; i < calendar.get(Calendar.YEAR) + 5; i++) {
            mcbxYear.addElement(i);
        }
        jCbxYear.setSelectedItem(calendar.get(Calendar.YEAR));

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPnlExhibitorFinancialList = new javax.swing.JPanel();
        jCbxYear = new javax.swing.JComboBox();
        jLblYear = new javax.swing.JLabel();
        jCbxWeek = new javax.swing.JComboBox();
        jLblWeek = new javax.swing.JLabel();
        lblFrom = new javax.swing.JLabel();
        lblTo = new javax.swing.JLabel();
        btnReport = new javax.swing.JButton();
        jLblFrom = new javax.swing.JLabel();
        jLblTo = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTPnlHtml = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jEditorPaneExhibitorFL = new javax.swing.JEditorPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblExhibitorFinancialList = new javax.swing.JTable(model){
            public boolean isCellEditable ( int rowIndex, int colIndex ) {
                return false ; //Disallow the editing of any cell
            }
        };

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPnlExhibitorFinancialList.setBorder(javax.swing.BorderFactory.createTitledBorder("Select Time"));
        jPnlExhibitorFinancialList.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jCbxYear.setModel(mcbxYear);
        jCbxYear.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCbxYearItemStateChanged(evt);
            }
        });

        jLblYear.setText("Year");

        jCbxWeek.setModel(mcbxWeek);
        jCbxWeek.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jCbxWeekItemStateChanged(evt);
            }
        });

        jLblWeek.setText("Week");

        lblFrom.setText("jLabel3");
        lblFrom.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        lblTo.setText("jLabel4");
        lblTo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        btnReport.setText("Report");
        btnReport.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        btnReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReportActionPerformed(evt);
            }
        });

        jLblFrom.setText("From:");

        jLblTo.setText("To:");

        javax.swing.GroupLayout jPnlExhibitorFinancialListLayout = new javax.swing.GroupLayout(jPnlExhibitorFinancialList);
        jPnlExhibitorFinancialList.setLayout(jPnlExhibitorFinancialListLayout);
        jPnlExhibitorFinancialListLayout.setHorizontalGroup(
            jPnlExhibitorFinancialListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlExhibitorFinancialListLayout.createSequentialGroup()
                .addGap(163, 163, 163)
                .addGroup(jPnlExhibitorFinancialListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPnlExhibitorFinancialListLayout.createSequentialGroup()
                        .addGroup(jPnlExhibitorFinancialListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLblWeek, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
                            .addGroup(jPnlExhibitorFinancialListLayout.createSequentialGroup()
                                .addComponent(jLblYear, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE)
                                .addGap(5, 5, 5)))
                        .addGap(18, 18, 18)
                        .addGroup(jPnlExhibitorFinancialListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCbxWeek, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jCbxYear, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(15, 15, 15)
                        .addGroup(jPnlExhibitorFinancialListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLblFrom, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
                            .addGroup(jPnlExhibitorFinancialListLayout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addComponent(jLblTo, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPnlExhibitorFinancialListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblTo, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
                            .addComponent(lblFrom, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE))
                        .addGap(37, 37, 37))
                    .addComponent(btnReport, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(134, 134, 134))
        );
        jPnlExhibitorFinancialListLayout.setVerticalGroup(
            jPnlExhibitorFinancialListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlExhibitorFinancialListLayout.createSequentialGroup()
                .addGroup(jPnlExhibitorFinancialListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLblWeek)
                    .addGroup(jPnlExhibitorFinancialListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jCbxWeek, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblFrom)
                        .addComponent(jLblFrom)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPnlExhibitorFinancialListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCbxYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLblYear)
                    .addComponent(lblTo)
                    .addComponent(jLblTo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnReport)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("EXHIBITOR FINANCIAL LIST");
        jLabel5.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jLabel5.setPreferredSize(new java.awt.Dimension(563, 116));

        jScrollPane3.setViewportView(jEditorPaneExhibitorFL);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTPnlHtml.addTab("HTML", jPanel1);

        tblExhibitorFinancialList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblExhibitorFinancialList.setPreferredSize(new java.awt.Dimension(563, 64));
        jScrollPane1.setViewportView(tblExhibitorFinancialList);

        jTPnlHtml.addTab("TABLE", jScrollPane1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTPnlHtml, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
                    .addComponent(jPnlExhibitorFinancialList, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlExhibitorFinancialList, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTPnlHtml, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                .addGap(32, 32, 32))
        );

        jTPnlHtml.getAccessibleContext().setAccessibleName("HTML");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCbxYearItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCbxYearItemStateChanged
//     Empties the list
        mcbxWeek.removeAllElements();
//        for i = 1 to 52
        for (int i = 1; i <= 52; i++) {
//            add 52 Week to show
            mcbxWeek.addElement(i);
        }
//        Call function WeekinYear in CalendarDateTime class
        if (cdt.WeekinYear(Integer.parseInt(jCbxYear.getSelectedItem().toString())) == 53) {
            mcbxWeek.addElement(53);
        }
    }//GEN-LAST:event_jCbxYearItemStateChanged

    private void jCbxWeekItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCbxWeekItemStateChanged
//        Create a new object
        Calendar c, d = new GregorianCalendar();
//        Get Year
        int year = Integer.parseInt(jCbxYear.getSelectedItem().toString());
//        Get week
        int week = jCbxWeek.getSelectedIndex() + 1;
        c = cdt.WeekToDate(week, year);
        d = cdt.WeekToDate(week, year);
//        Forward 6 day
        d.add(Calendar.DATE, 6);
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        
        //jLabel3.setText(sdf.format(c.getTime()));
        lblFrom.setText(sdf.format(c.getTime()));
        lblTo.setText(sdf.format(d.getTime()));

    }//GEN-LAST:event_jCbxWeekItemStateChanged

    private void btnReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReportActionPerformed
        setModelH();
        setModelT();
    }//GEN-LAST:event_btnReportActionPerformed

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new ReportExhibitorFinancial().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnReport;
    private javax.swing.JComboBox jCbxWeek;
    private javax.swing.JComboBox jCbxYear;
    private javax.swing.JEditorPane jEditorPaneExhibitorFL;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLblFrom;
    private javax.swing.JLabel jLblTo;
    private javax.swing.JLabel jLblWeek;
    private javax.swing.JLabel jLblYear;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPnlExhibitorFinancialList;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTPnlHtml;
    private javax.swing.JLabel lblFrom;
    private javax.swing.JLabel lblTo;
    private javax.swing.JTable tblExhibitorFinancialList;
    // End of variables declaration//GEN-END:variables

//    Control Model
    public void setModelT() {
        try {
           att = new BssGetDataReportExhibitorFinancialList();
//            Create a new object of table
            model = new DefaultTableModel();
//            Create two object of Vector
            Vector v = new Vector();
            Vector v1 = new Vector();
//            add values from Form
            v.add(String.valueOf(lblFrom.getText().trim()));
            v1.add(String.valueOf(lblTo.getText().trim()));

//            Create two object of Vector
            Vector v0 = new Vector();
//            Get v0 from object GetDataReportExhibitorFinancialList
            v0 = att.getExhibitorFinancialList(v, v1);

            //ExhibitorID,Name,Address,IndentityCardNumber
            model.addColumn("ExhibitorID");
            model.addColumn("FirstName");
            model.addColumn("LastName");
            model.addColumn("Address");
            model.addColumn("AccountBank");
            model.addColumn("BankName");
            model.addColumn("RegisterDate");

//            System.out.println(1+" "+(Vector) v0.get(1));
//            System.out.println(2+" "+(Vector) v0.get(2));
//            System.out.println(3+" "+(Vector) v0.get(3));
//            System.out.println(4+" "+(Vector) v0.get(4));
//            System.out.println(5+" "+(Vector) v0.get(5));
//            System.out.println(6+" "+(Vector) v0.get(6));
            System.out.println(v0.size());
            for (int i = 0; i < v0.size(); i++) {

                model.addRow((Vector) v0.get(i));
                System.out.println(i+" "+v0.get(i));
                System.out.println("String"+ i+" "+v0.get(i).toString());
            }
//            Set Model
            tblExhibitorFinancialList.setModel(model);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

     public void setModelH() {
        try {

            att = new BssGetDataReportExhibitorFinancialList();
//            Create a new object of table
//            model = new DefaultTableModel();
//            Create two object of Vector
            Vector v = new Vector();
            Vector v1 = new Vector();
//            add values from Form
            v.add(String.valueOf(lblFrom.getText().trim()));
            v1.add(String.valueOf(lblTo.getText().trim()));

//            Create two object of Vector
            Vector v0 = new Vector();
//            Get v0 from object GetDataReportExhibitorFinancialList
            v0 = att.getExhibitorFinancialList(v, v1);
            

            att.writeHTML(v0);
            //ExhibitorID,Name,Address,IndentityCardNumber
//            model.addColumn("ExhibitorID");
//            model.addColumn("FirstName");
//            model.addColumn("LastName");
//            model.addColumn("Address");
//            model.addColumn("AccountBank");
//            model.addColumn("BankName");

//            for (int i = 0; i < v0.size(); i++) {
//
//                model.addRow((Vector) v0.get(i));
//                System.out.println(i+" "+v0.get(i));
//            }
//            Set Model
//            tblExhibitorFinancialList.setModel(model);

          File file=new File(".");
          jEditorPaneExhibitorFL.setPage("file:///"+file.getCanonicalPath()+"/ReportExhibitorFinancialList.html");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    

}
